##########################################
# REPLICATION OF: 
#
# State Reach and Development in Africa since the 1960s: New data and analysis
#
# Political Science Research and Methods
#
# By Carl Müller-Crepon, 2021
#
##########################################

# INIT ###################################

# Clear environment
rm(list = ls())
gc()

# Set working directory
setwd("~/Projects/phd_code/post-colonial_inequality/state_expansion/replication")

# Packages
source("code/packages.R")

# Functions
source("code/functions.R")

# Results Directory Structure
for(d in c("figures", "tables", "numbers")){
  dir.create(file.path("results", d), 
             recursive = T, showWarnings = F)
}
tab.path <- "results/tables/"
fig.path <- "results/figures/"
num.path <- "results/numbers/"

# Number of CPUs?
#   Set to multiple CPUs to speed up parts of the analysis. 
#   Needs a lot of RAM. 
ncore <- 1 

# DESCRIPTIVES #############################

## Input data
source("code/plots_inputs.R")

## State Reach Data: Descriptives and disaggregation
source("code/plots_statereach.R")

## Voronoi - Cell comparison
source("code/vor_vs_cells.R")

# VALIDATION STATE CAPACITY INDEX ##########

source("code/analysis_afrobarometer.R")


# ANALYSIS #################################

source("code/analysis_main.R")


# REMOVE TEMPORARY FILES & CLEANUP #########

## Remove temporary results file
unlink("data/tempresults.rds")
unlink("error.txt") ## File with potential errors resulting from parallelization

## Clear environment
rm(list = ls())
gc()

